<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <th:block th:include="include :: header('用户列表')" />
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="post-form">
                <div class="select-list">
                    <ul>
                        <li>
                            用户名：<input type="text" name="username"/>
                        </li>
                        <li>
                            地点<select name="building">
                            <option value="">所有</option>
                            <option th:each="list:${bl}" th:text="${list.building}" th:value="${list.id}"></option>
                        </select>
                        </li>
                        <li>
                            身份：<select name="identify" >
                            <option value="">所有</option>
                            <option value="1">送货员</option>
                            <option value="0">普通用户</option>
                        </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            				<a class="btn btn-warning" onclick="$.table.exportExcel()" >
            		            <i class="fa fa-download"></i> 导出
            		        </a>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
    var removeFlag = [[${@permission.hasPermi('water:user:remove')}]];
    var editFlag = [[${@permission.hasPermi('water:user:edit')}]];
    var datas = [[${@dict.getType('sys_normal_disable')}]];
    var prefix = ctx + "water";

    $(function() {

        var options = {
            url:  prefix+ "/listUser",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/removeUser",
            exportUrl: prefix + "/export",
            modalName: "商品列表",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '用户编号'
                },
                {
                    field: 'username',
                    title: '用户名',
                },
                {
                    field: 'address',
                    title: '地址',
                    //查询数据库，找到sort_id对应的分类名
                },
                {
                    field: 'phone',
                    title: '电话',
                },
                {
                    field: 'identify',
                    title: '身份',
                    formatter:function(value,row,index){
                        var actions=[];
                        if(value==1){
                            actions.push('<span style="color: red">送货员</span>&nbsp;');
                        }else if(value ==0){
                            actions.push('<span style="color: darkseagreen">普通用户</span>&nbsp;');

                        }else{
                            actions.push('<span style="color: darkseagreen">未识别身份</span>&nbsp;');
                        }
                        return actions.join('');
                    }

                },

                {
                    visible: editFlag == 'hidden' ? false : true,
                    // title: '状态',
                    align: 'center',
                    formatter: function (value, row, index) {
                        return statusTools(row);
                    }
                },

                {
                    title: '操作',
                    align: 'center',
                    formatter: function(value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.id+'\')"><i class="fa fa-remove"></i>删除</a>&nbsp;');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });

    function  addChildren(id) {
        $.modal.open('添加子商品', prefix + "/addChildren/"+id, '666', '500');
    }
    function showChildren(id) {
        var url = prefix +"/showChildren/"+id;
        $.modal.openTab("查看子商品",url);
    }
    /* 管理进度 */
    function manage(id) {
        var url = prefix + '/showChildren/' + id;
        //第一个参数是标签的名称
        $.modal.openTab("子商品管理", url);
    }
    /* 商品上架 */
    function statusTools(row) {
        if (row.identify == 0) {
            return '<i class=\"fa fa-toggle-off text-info fa-2x\" onclick="enable(\'' + row.id + '\')"></i> ';
        } else {
            return '<i class=\"fa fa-toggle-on text-info fa-2x\" onclick="disable(\'' + row.id + '\')"></i> ';
        }
    }
    /* 商品下架 */
    function disable(id) {
        $.modal.confirm("确认要下架商品吗？", function() {
            $.operate.post(prefix + "/changeUserIdentify", { "id": id,"identify": 0});
        })
    }
    /* 商品上架 */
    function enable(id) {
        $.modal.confirm("确认要上架商品吗？", function() {
            $.operate.post(prefix + "/changeUserIdentify", { "id": id, "identify": 1});
        })
    }
</script>
</body>
</html>